<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon :icon-class="isScreenFull ? 'exit-fullscreen' : 'fullscreen'" class="fullscreen" @click="toggleScreen" />
  </div>
</template>

<script>
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isScreenFull: false// 全屏状态
    }
  },
  mounted() {
    // 监听全屏的状态是否切换
    screenfull.on('change', () => {
      this.isScreenFull = screenfull.isFullscreen
    })
  },

  methods: {
    // 点击全屏
    toggleScreen() {
      screenfull.toggle()
      // 全屏切换状态,点后取反
    //   this.isScreenFull = !this.isScreenFull
    }

  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
